package com.sanyang.pda.presenter;

import com.sanyang.pda.bean.BindBgvinfoBean;
import com.sanyang.pda.bean.LssuedStorageBean;
import com.sanyang.pda.bean.TakeStockListBean;
import com.sanyang.pda.bean.request.PdaCreateTaskRequest;
import com.sanyang.pda.contract.LssuedWorkContract;
import com.sanyang.pda.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import java.util.List;

import io.reactivex.functions.Consumer;

public class LssuedWorkPresenter extends BasePresenter<LssuedWorkContract .View> implements LssuedWorkContract.Presenter {

    @Override
    public void getStorageLocationsQuickList(String slType) {
        NetUtils.geApi().getStorageLocationsQuickList(slType)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<LssuedStorageBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<LssuedStorageBean>> takeStockListBeanBaseAppEntity) throws Exception {
                        getView().setList(takeStockListBeanBaseAppEntity.getData(),slType);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void getPadBindBgvinfoByPdaSn(String pdaSN) {
        NetUtils.geApi().getPadBindBgvinfoByPdaSn(pdaSN)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<BindBgvinfoBean>>() {
                    @Override
                    public void accept(BaseAppEntity<BindBgvinfoBean> takeStockListBeanBaseAppEntity) throws Exception {
                        if (takeStockListBeanBaseAppEntity.getData() != null){
                            getView().setBindBean(takeStockListBeanBaseAppEntity.getData());
                        }else {
                            getView().nobBind();
                        }

                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void getContinueTask(String pdaSN, String agvkey) {
        NetUtils.geApi().getContinueTask(pdaSN,agvkey)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<Object>>() {
                    @Override
                    public void accept(BaseAppEntity<Object> takeStockListBeanBaseAppEntity) throws Exception {
                        getView().showMessage(takeStockListBeanBaseAppEntity.getMessage());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void ebsyPdaCreateTask(PdaCreateTaskRequest body) {
        NetUtils.geApi().ebsyPdaCreateTask(body)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<Object>>() {
                    @Override
                    public void accept(BaseAppEntity<Object> takeStockListBeanBaseAppEntity) throws Exception {
                        getView().showMessage(takeStockListBeanBaseAppEntity.getMessage());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
